package com.brillilab.service.core.experiments.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.brillilab.dao.mapper.experiments.PlateStepRelateMapper;
import com.brillilab.domain.po.experiments.PlateStepRelate;
import com.brillilab.service.core.experiments.IPlateStepRelateService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 多孔板步骤关联
 * @author WuMenghao
 * @time   2019/04/17
 */
@Service
@Transactional
public class PlateStepRelateServiceImpl implements IPlateStepRelateService {

    @Resource
    private PlateStepRelateMapper plateStepRelateMapper;

    @Override
    public boolean insert(PlateStepRelate relate) {
        return plateStepRelateMapper.insert(relate) > 0;
    }

    @Override
    public List<PlateStepRelate> selectList(Long experimentId,Long plateId,Long phaseId,Long stepId) {
        return plateStepRelateMapper.selectList(
                new LambdaQueryWrapper<PlateStepRelate>()
                        .eq(PlateStepRelate::getExperimentId,experimentId)
                        .eq(PlateStepRelate::getPlateId,plateId)
                        .eq(PlateStepRelate::getPhaseId,phaseId)
                        .eq(PlateStepRelate::getStepId,stepId));
    }

    @Override
    public List<PlateStepRelate> selectByExperimentIdAndPhaseIdAndGtStepSort(Long experimentId,Long phaseId,Integer stepSort) {
        return plateStepRelateMapper.selectList(
                new LambdaQueryWrapper<PlateStepRelate>()
                        .eq(PlateStepRelate::getExperimentId,experimentId)
                        .eq(PlateStepRelate::getPhaseId,phaseId)
                        .le(PlateStepRelate::getStepSort,stepSort));
    }

    @Override
    public boolean deleteByPlateId(Long plateId) {
        return plateStepRelateMapper.delete(
                new LambdaQueryWrapper<PlateStepRelate>()
                        .eq(PlateStepRelate::getPlateId,plateId)) >0;
    }

	@Override
	public List<PlateStepRelate> selectStepRelateList(Long experimentId) {
		return plateStepRelateMapper.selectList(
                new LambdaQueryWrapper<PlateStepRelate>()
                        .eq(PlateStepRelate::getExperimentId,experimentId));
	}
}
